﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Globalization;

namespace Kokomo
{
	public class ComboHexConverter : TypeConverter
	{
		static ComboHexConverter()
		{
			Default = new ComboHexConverter();
		}

		public static ComboHexConverter Default { get; private set; }

		public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
		{
			if (destinationType == null) throw new ArgumentNullException("destinationType");

			bool canConvert =
				(destinationType == typeof(string))
				;

			return canConvert;
		}

		public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
		{
			if (value == null) throw new ArgumentNullException("value");
			if (destinationType == null) throw new ArgumentNullException("destinationType");
			if (destinationType != typeof(string)) throw new InvalidOperationException("Can only convert to string");

			return string.Format("{0} [0x{0:X8}]", value);
		}
	}
}
